import cv2
import numpy as np
import os
 
save_path = './aruco_marker'
if not os.path.exists(save_path):
    print('文件夹不存在{0}，创建了此文件夹'.format(save_path))
    os.mkdir(save_path)

dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
 
markerImage = np.zeros((200, 200), dtype=np.uint8)
ids = [i for i in range(30)] # [9]
for i in ids:
    markerImage = cv2.aruco.generateImageMarker(dictionary, i, 200, markerImage, 1)
    firename= '{0}/aruco_6x6_250_{1}.png'.format(save_path, i)
    res = cv2.imwrite(firename, markerImage)
    if res:
         print('board图片已经成功生成，位于' + '{0}/aruco_6x6_250_{1}.png'.format(save_path, i))
    else:
        print('未能成功生成!')